package pub.zengzhipeng.jvm;

public class JMM {

    private static  volatile  boolean sign = false;


    public static void main(String[] args) throws InterruptedException {
        Thread thread1 = new Thread(()->{
            try {
                Thread.sleep(1000L);
                System.out.println("I " + Thread.currentThread().getName() );
                sign = true;
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });

        Thread thread2 = new Thread(()->{
           while (!sign){
               System.out.println(Thread.currentThread().getName());
               try {
                   Thread.sleep(100L);
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
           }
        });

        thread2.start();

        thread1.start();
        thread2.join();


    }

}
